//
//  HNSH_WithdrawalRecordCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/6/14.
//

#import "HNSH_WithdrawalRecordCell.h"

@interface HNSH_WithdrawalRecordCell ()

/* bgView */
@property(nonatomic, strong) UIView *bgView;

/* 图片 */
@property(nonatomic, strong) UIImageView *icon;

/* 标题 */
@property(nonatomic, strong) UILabel *titleLabel;
/* 描述 */
@property(nonatomic, strong) UILabel *desLabel;
/* 金额 */
@property(nonatomic, strong) UILabel *moneyLabel;

@end

@implementation HNSH_WithdrawalRecordCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self configView];
    }
    return self;
}

- (void)configView {
    [self addAllViews];
    [self addAllLayout];
}

- (void)setModel:(HNSH_WithdrawalRecordModel *)model {
    self.desLabel.text = model.create_time;
    self.moneyLabel.text = [NSString stringWithFormat:@"%@元",model.money];
    
    if (model.status == 10) {//处理中
        self.titleLabel.text = @"处理中";
        self.icon.image = [UIImage imageNamed:@"withdrawal_icon_chuli"];
    } else if (model.status == 100 || model.status == 20) {//提现成功
        self.titleLabel.text = @"提现成功";
        self.icon.image = [UIImage imageNamed:@"withdrawal_icon_mai"];
    } else {//提现失败
        self.titleLabel.text = @"提现失败";
        self.icon.image = [UIImage imageNamed:@"withdrawal_icon_fail"];
    }
}

- (void)setRechargeModel:(HNSH_WithdrawalRecordModel *)rechargeModel {
    _rechargeModel = rechargeModel;
    self.desLabel.text = rechargeModel.create_time;
    self.moneyLabel.text = [NSString stringWithFormat:@"%@元",rechargeModel.amount];
    
    //0:审核中 1:充值成功 2:审核拒绝
    if (rechargeModel.status == 0) {//处理中
        self.titleLabel.text = @"处理中";
        self.icon.image = [UIImage imageNamed:@"withdrawal_icon_chuli"];
    } else if (rechargeModel.status == 1) {//充值成功
        self.titleLabel.text = @"充值成功";
        self.icon.image = [UIImage imageNamed:@"withdrawal_icon_mai"];
    } else {//提现失败
        self.titleLabel.text = @"充值失败";
        self.icon.image = [UIImage imageNamed:@"withdrawal_icon_fail"];
    }
}

- (void)addAllViews {
    self.contentView.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
    
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.icon];
    [self.bgView addSubview:self.titleLabel];
    [self.bgView addSubview:self.desLabel];
    [self.bgView addSubview:self.moneyLabel];
}

- (void)addAllLayout {
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
    }];
    self.bgView.layer.cornerRadius = 8;
    self.bgView.layer.masksToBounds = YES;
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.centerY.mas_equalTo(self.bgView.mas_centerY);
        make.width.height.mas_equalTo(32);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(60);
        make.top.mas_equalTo(13);
        make.height.mas_equalTo(20);
    }];
    
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(60);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(2);
        make.height.mas_equalTo(16);
    }];
    
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.centerY.mas_equalTo(self.bgView.mas_centerY);
        make.height.mas_equalTo(22);
    }];
}

#pragma mark lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UIImageView *)icon {
    if (!_icon) {
        _icon = [[UIImageView alloc]init];
        _icon.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _icon;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = @"打款成功";
        _titleLabel.textColor = [UIColor colorWithHexString:@"#333333"];
        _titleLabel.font = [UIFont boldSystemFontOfSize:14];
    }
    return _titleLabel;
}

- (UILabel *)desLabel {
    if (!_desLabel) {
        _desLabel = [[UILabel alloc]init];
        _desLabel.text = @"2022-01-13  20:17:53";
        _desLabel.textColor = [UIColor colorWithHexString:@"#999999"];
        _desLabel.font = [UIFont systemFontOfSize:11];
    }
    return _desLabel;
}

- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc]init];
        _moneyLabel.text = @"1.99元";
        _moneyLabel.textColor = [UIColor colorWithHexString:@"#F73525"];
        _moneyLabel.font = [UIFont boldSystemFontOfSize:16];
    }
    return _moneyLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
